import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text ,Button,Video } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import '../grouplist/grouplist.scss'




export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      reslut: [],
      updatete: true,
      mytime: null,
      gglist:[],
      qid:"",
      catlist:[],
      catid:0,
      videosrc:'',
      iszb:''
    }
  }
  config = {
    navigationBarTitleText:'门店列表'
  }

  componentWillMount () {
  	var _this=this;
  	Taro.showLoading({title: '获取门店中'})
  	setTimeout(function(){
    	_this.getdate()
    },600)
    this.getvideo()
  }
  componentDidShow () {
  	
  }
  componentDidUpdate () {

  }

  open(url,type){
    this.$preload({
      type:type
    })
    CommonJs.open(url);
  }

  
  getvideo(){
    var url='/advert/papi/v1.9/advert?advertTypeId.equals=6';
    var _this=this;
    CommonJs.ajaxRequest(url,'','GET',function(res){
      var arr=res.data.list;
      if(arr.length>0){
        _this.setState({
	        videosrc:arr[0].picUrl
	      })
      }
    })
  }
  
  
  getdate(){
    var _this=this
    var webinfo=Taro.getStorageSync('webinfo')
    this.setState({
      iszb:webinfo.iszb
    })
    //var url='/shop/papi/v1.9/shops?dealerId.equals='+webinfo.dealerId
    var url='/shop/papi/v1.9/members/queryShopByDealerId/'+webinfo.dealerId
    CommonJs.ajaxRequest(url,'','GET',function(res){
    	var ret=res.data;
      _this.setState({
        reslut:ret
      })
      if(ret.length==1){
      	_this.getnav(ret[0].id,ret[0].clusterId)
      }
    })
  }
  getnav(id,qid){
    this.$preload({
	    type:1
	  })
    var dateinfo = Taro.getStorageSync('dateinfo');
		if(!dateinfo){
			dateinfo={}
		}
		dateinfo.qid=qid;
	  Taro.setStorage({key:'dateinfo',data:dateinfo})
    var webinfo=Taro.getStorageSync('webinfo')
    Taro.setStorage({key:'shopId',data:id})
    Taro.setStorage({key:'dealerId',data:webinfo.dealerId})
    CommonJs.openTo('/pages/mall/index')
  }
	opendetails(url){
    CommonJs.openTo(url);
  }
  render () {
    const resy = this.state.reslut
    return (
    	<View className='page'>
       
	      <View className='qun-banner'>
	      	<View className='hd-video'>
	      		<Video
		          src={this.state.videosrc}
		          controls={true}
		          autoplay={false}
		          initialTime='0'
		          id='video'
		          loop={false}
		          muted={false}
		        />
	      	</View>
          
          <View className='qun-licon bdk-list'>
            {resy.map((item, index) => (
            <View className='qun-lists' onClick={this.getnav.bind(this,item.id,item.clusterId)}>
              <View className='qun-toxnli'>
                <View className='qun-lfimg'>
                  <Image className='qun-userg' mode='aspectFill' src={item.rotationPictures ? item.rotationPictures : 'https://minichat.g2ma.com/kedouimg/A6984900727459logo.png'}></Image>
                </View>
                <View className='qun-lfinfo'>
                  <View className='qun-inyi'>
                    <Text className='qun-botn'>{item.name}</Text>
                    <Text className='qun-gntn'>{item.address}</Text>
                  </View>

                </View>
              </View>
            </View>
            ))}
          </View>
	      </View>

      </View>
    )
  }
}
